<template>
  <view class="order-conatiner">
    <view class="order-detail">
      <view class="row">
        <text class="name">订单编号:</text><text>{{orderId}}</text>
      </view>
      <view class="row">
        <text class="name">订单价格：</text><text>{{ `￥${detailDataObj.Order_price}` }}</text>
      </view>
      <view class="row">
        <text class="name">优惠金额：</text><text>{{ `￥${Pay_price}` }}</text>
      </view>
      <view class="row">
        <text class="name">订单金额：</text><text>{{ `￥${(
                        Number(detailDataObj.Order_price) - Number(Pay_price)
                      ).toFixed(2)}` }}</text>
      </view>
    </view>
    <view class="order-detail">
      <view class="row">
        <text class="name">通宝抵扣:</text><text>{{`-￥${tongbaoPay_price}` }}</text>
      </view>
      <view class="row">
        <text class="name">妖豆抵扣:</text><text>{{`-￥${yaodouPay_price}` }}</text>
      </view>
      <view class="row">
        <text class="name">现金支付:</text><text class="pay_num">{{`￥${detailDataObj.Order_Pay_price}` }}</text>
      </view>
    </view>
  </view>

</template>

<script>
  import md5 from "js-md5"
  export default {
    data() {
      return {
        orderId: 0,
        Bid: 65,
        detailDataObj: '',
        Pay_price: 0,
        tongbaoPay_price: 0,
        yaodouPay_price: 0,
      };
    },
    onLoad(options) {
      console.log(options)
      if (options.orderId) {
        this.orderId = options.orderId;
        this.md5Fn(this._queryorderpayinfo)
      }

    },
    methods: {
      md5Fn(cb) {
        //debugger
        const userId = JSON.parse(uni.getStorageSync('userinfo')).userId;
        const Md5 = md5(`Bid=65&orderId=${this.orderId}&UserId=${userId}&key=C63A39419CE64F258ADFE3FAF5E63477`);
        this.signMd5 = Md5;
        this.userId = userId;
        cb && cb()
      },
      _queryorderpayinfo() {
        uni.$http.get(
          `/WebApi/Wap/Action?t=queryorderpayinfo&data=${JSON.stringify({Bid:this.Bid,UserId:this.userId,Sign:this.signMd5,orderId:this.orderId})}`
        ).then(({
            data: res
          }) => {
            console.log(res);
            this.detailDataObj = res.data;
            if (res.data.Order_Pay_info.length == 0) {
              this.Pay_price = 0;
              this.tongbaoPay_price = 0;
              this.yaodouPay_price = 0;
            } else {
              let item = res.data.Order_Pay_info.find((item) => {
                return item.Pay_type == 1;
              });
              if (item) {
                this.Pay_price = item.Pay_price;
              } else {
                this.Pay_price = 0;
              }

              res.data.Order_Pay_info.map((current) => {
                if (current.Pay_type == 3) {
                  this.tongbaoPay_price = current.Pay_price;
                } else if (current.Pay_type == 2) {
                  this.yaodouPay_price = current.Pay_price;
                } else {
                  this.tongbaoPay_price = 0;
                  this.yaodouPay_price = 0;
                }
              });
              }
            })
        }
      }
    }
</script>

<style lang="scss">
  .order-detail {
    width: 662rpx;
    margin:0 auto;
    padding:24rpx;
    mini-height: 321px;
    background: #FFFFFF;
    border-radius: 12px;
    margin-bottom:20rpx;
    .row{
      font-size: 26rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #666666;
      margin-bottom:31rpx;
      .name{
        font-size: 26rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #1A1A1A;
        margin-right:10rpx;
      }
      .pay_num{
        font-size: 26rpx;
        font-family: PingFang SC;
        font-weight: bold;
        color: #E33F2A;
      }
    }

  }
</style>
